﻿Imports System.Windows.Threading
Imports System.Windows.Media.Animation

Partial Public Class Working

    Private Delegate Sub UpdateUIHandler(ByVal Action As Working.Actions, ByVal MessageBox As String, ByVal Status As String)

    Public Window As MainWindow

    Public Sub Update(ByVal Action As Working.Actions, ByVal MessageBox As String, ByVal Status As String)
        Dim UpdateUIHandler As UpdateUIHandler = New UpdateUIHandler(AddressOf UpdateUI)
        Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, UpdateUIHandler, Action, MessageBox, Status)
    End Sub

    Private Sub UpdateUI(ByVal Action As Working.Actions, ByVal MessageBox As String, ByVal Status As String)
        Try
            Select Case Action
                Case Actions.Start
                    CType(Window.Resources("ShowWorkingControl"), Storyboard).Begin(Window)
                Case Actions.Progress

                Case Actions.Stop
                    CType(Window.Resources("HideWorkingControl"), Storyboard).Begin(Window)
            End Select
            Dim place As Integer = Trace.Items.Add(Status)
            Me.Status.Content = Status
            Me.MessageBox.Text = MessageBox
            Trace.ScrollIntoView(Trace.Items(place))
        Catch ex As Exception
            Me.Status.Content = "An error occured"
            Me.MessageBox.Text = ex.ToString
        End Try
       
    End Sub

    Public Enum Actions
        Start
        Progress
        [Stop]
    End Enum


End Class
